package com.offcn.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.offcn.pojo.Ordersetting;
import com.offcn.service.OrdersettingService;
import com.offcn.utils.MessageConstant;
import com.offcn.utils.POIUtils;
import com.offcn.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.rmi.MarshalException;
import java.util.List;
import java.util.Map;

/**
 * @Author: wy
 * @Date: 2022/9/1 10:39
 */
@Controller
@ResponseBody
@RequestMapping("ordersetting")
public class OrdersettingController {

    private Result result;

    @Reference
    private OrdersettingService ordersettingService;

    //exal上传
    @RequestMapping("uploadTempleate")
    public Result uploadTempleate(@RequestParam(value = "excelFile") MultipartFile excelFile) {

        try {
            List<String[]> ordersetting = POIUtils.readExcel(excelFile);
            ordersettingService.uploadTempleate(ordersetting);
            result = new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS, null);
        } catch (Exception e) {
            result = new Result(true, MessageConstant.IMPORT_ORDERSETTING_FAIL, null);
        }
        return result;
    }


    //显示 预约人数 getOrdersettingByDate
    @RequestMapping("getOrdersettingByDate")
    public List<Map<String, Object>> getOrdersettingByDate(String date) {
        List<Map<String, Object>> mapList = ordersettingService.getOrdersettingByDate(date);
        return mapList;
    }

    //预约人数的修改 editNumberByDate
    @RequestMapping("editNumberByDate")
    public Result editNumberByDate(@RequestBody Ordersetting ordersetting){
        try {
            ordersettingService.editNumberByDate(ordersetting);
            result = new Result(true, MessageConstant.ORDERSETTING_SUCCESS, null);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.ORDERSETTING_FAIL, null);
        }
        return result;
    }

}
